package org.zhxy.zhxy.service.impl;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zhxy.zhxy.dao.HomeDao;
import org.zhxy.zhxy.service.HomeService;
import org.zhxy.zhxy.utils.Result;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class HomeServiceImpl implements HomeService {

    @Autowired
    private HomeDao homeDao;

    @Override
    public Result statusChart() {
        int openClassroomNum = homeDao.getOpenClassroomNum();
        int closeClassroomNum = homeDao.getCloseClassroomNum();
        Map<String, Integer> res = new HashMap<>();
        res.put("openClassroomNum", openClassroomNum);
        res.put("closeClassroomNum", closeClassroomNum);
        return Result.success(res);
    }

    @Override
    public Result useChart() {
        LocalDateTime now = LocalDateTime.now();
        Date firstMonthStartTime =  DateUtil.beginOfMonth(Date.from(now.minusMonths(4).atZone(ZoneId.systemDefault()).toInstant()));
        Date firstMonthEndTime = DateUtil.endOfMonth(firstMonthStartTime);
       /* Date secondMonthStartTime = DateUtil.beginOfMonth(Date.from(now.minusMonths(3).atZone(ZoneId.systemDefault()).toInstant()));
        Date secondMonthEndTime = DateUtil.endOfMonth(secondMonthStartTime);
        Date thirdMonthStartTime = DateUtil.beginOfMonth(Date.from(now.minusMonths(2).atZone(ZoneId.systemDefault()).toInstant()));
        Date thirdMonthEndTime = DateUtil.endOfMonth(thirdMonthStartTime);
        Date fourthMonthStartTime = DateUtil.beginOfMonth(Date.from(now.minusMonths(1).atZone(ZoneId.systemDefault()).toInstant()));
        Date fourthMonthEndTime = DateUtil.endOfMonth(fourthMonthStartTime);*/
        Date fifthMonthStartTime = DateUtil.beginOfMonth(Date.from(now.atZone(ZoneId.systemDefault()).toInstant()));
        Date fifthMonthEndTime = DateUtil.endOfMonth(fifthMonthStartTime);
        log.info("firstMonth：{},{}",firstMonthStartTime,firstMonthEndTime);
     /*   log.info("secondMonth：{},{}",secondMonthStartTime,secondMonthEndTime);
        log.info("thirdMonth：{},{}",thirdMonthStartTime,thirdMonthEndTime);
        log.info("fourthMonth：{},{}",fourthMonthStartTime,fourthMonthEndTime);*/
        log.info("fifthMonth：{},{}",fifthMonthStartTime,fifthMonthEndTime);

        List<Map<String,Integer>> res = homeDao.getOftenUseClassroomTopTen(firstMonthStartTime,fifthMonthEndTime);
     /*   Map<String,Integer> secondMonthList = homeDao.getOftenUseClassroomTopTen(secondMonthStartTime,secondMonthEndTime);
        Map<String,Integer> thirdMonthList = homeDao.getOftenUseClassroomTopTen(thirdMonthStartTime,thirdMonthEndTime);
        Map<String,Integer> fourthMonthList = homeDao.getOftenUseClassroomTopTen(fourthMonthStartTime,fourthMonthEndTime);
        Map<String,Integer> fifthMonthList = homeDao.getOftenUseClassroomTopTen(fifthMonthStartTime,fifthMonthEndTime);*/
        log.info("res：{}",res);
        return Result.success(res);
    }
}
